package com.chixing.day20_annotation_jdk8;

import java.util.Arrays;
import java.util.List;


public class Excise {
    protected static void test(){
        List<Integer> costBeforeTax = Arrays.asList(100,200,300,400,500);
        for (Integer cost : costBeforeTax){
            double price = cost + 0.12 * cost;
            System.out.println(price);
        }
        List<Integer> costBeforeTax2 = Arrays.asList(100,200,300,400,500);
        costBeforeTax2.stream()//获取stream对象
            .map((cost) -> cost + 0.12 * cost)  //对每一个元素加上 12% 的税
                .forEach(System.out::println); //遍历

    }

    protected static void test1(){
        List<Integer> costBeforeTax = Arrays.asList(100,200,300,400,500);
        double total = 0;
        for (Integer cost : costBeforeTax){
            double price = cost +0.12 * cost;
            total = total + price;
        }
        System.out.println("Total: " + total);

        List<Integer> costBeforeTax2 = Arrays.asList(100,200,300,400,500);
        double bill = costBeforeTax2.stream()
                .map((cost) -> cost + 0.12 *cost)
                .reduce((sum,cost) -> sum + cost)
                .get();
        System.out.println("Total: " + bill);
    }
}
